package com.liwq.base.sync;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : liwq
 * @version : 1.0
 * @date : 2023/1/29
 **/
public class LockTicket {

    private int num = 30;

    private final ReentrantLock lock = new ReentrantLock(true);


    public void sale() {
        lock.lock();
        //判断是否有票
        if (num > 0) {
            System.out.println(Thread.currentThread().getName() + " ：卖出" + (num--) + " 剩余：" + num);
        }
        lock.unlock();


    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}
